//加载样式
var cssSrc = "";
for (var i = 0; i < document.getElementsByTagName('script').length; i++) {
    var jsscr = document.getElementsByTagName('script')[i].src;
    if (jsscr.indexOf("cAlert.js") > 0) {
        cssSrc = jsscr.replace("cAlert.js", "MsgBox.css");
    }
}
var cssTag = document.createElement('link');
cssTag.setAttribute('rel', 'stylesheet');
cssTag.setAttribute('type', 'text/css');
cssTag.setAttribute('href', '' + cssSrc + '');
document.getElementsByTagName('head')[0].appendChild(cssTag);
//end
var isShow = false;
//取标签的绝对位置
function Offset(e) {
    var t = e.offsetTop;
    var l = e.offsetLeft;
    var w = e.offsetWidth;
    var h = e.offsetHeight - 2;
    while (e = e.offsetParent) {
        t += e.offsetTop;
        l += e.offsetLeft;
    }
    return {
        top: t,
        left: l,
        width: w,
        height: h
    }
}
/************弹出网页的操作**************/

//function SearchShop() {
//    if (window.showModalDialog != null)//IE判断
//    {
//        var returnValue = window.showModalDialog("WishMemberAdd.aspx", "", "dialogWidth=800px;dialogHeight=430px");
//        if (returnValue != null) {
//            window.location.href = location.href;
//        }
//        return;
//    } else {
//        this.returnAction = function(returnValue) {
//            if (returnValue != null) {
//                window.location.href = location.href;
//            }
//        }
//    }
//    window.open("WishMemberAdd.aspx", "", "height=430px,width=800px");
//    return;
//}
function SearchShop(url, width, height) {
    var dialogInfo = "";
    if (width > 0) {
        dialogInfo = "dialogWidth=" + width + "px;dialogHeight=" + height + "px";
    }
    else {
        dialogInfo = "dialogWidth=800px;dialogHeight=400px";
    }
    if (window.showModalDialog != null)//IE判断
    {
        var returnValue = window.showModalDialog(url, "", dialogInfo);
        if (returnValue != null) {
            window.location.href = window.location.href + '?sid=' + parseInt(10 * Math.random());
        }
        return;
    } else {
        this.returnAction = function(returnValue) {
            if (returnValue != null) {
                window.location.href = window.location.href;
            }
        }
    }
    return;
}
function ReturnShopId() {
    if (window.showModalDialog != null)//IE判断
    {
        window.returnValue = "aaa";
        window.close(); //firefox不支持
    }
    else {
        window.opener.returnAction("aaa");
        top.close(); //IE和FireFox都支持
    }
}
/*************弹出层的操作*********************
content:要现实的内容[url.obj,content]
position:如果不为空，则显示在传过来的对象处，如果为空，剧中
height对象的高度；width:对象的宽度
type:[1:url;2:obj;3:content]
*/

function show(title, content, height, width, type, positionObj) {
    if (isShow) {
        return;
    } else {
        isShow = true;
    }
    hideElementAll();
    //var document = parent.document;
    type = (type == undefined) ? 2 : type;
    height = (height == undefined) ? 600 : height;
    width = (width == undefined) ? 800 : width;
    var sWidth = document.documentElement.scrollWidth;
    var sHeight = document.documentElement.offsetHeight;
    //+document.documentElement.scrollTop;//(document.documentElement.offsetHeight - document.body.offsetHeight > 200) ? document.documentElement.offsetHeight : document.body.offsetHeight;

    var mHeight = document.documentElement.scrollHeight; //(sHeight > screeH) ? sHeight : screeH;
    mHeight = (mHeight > window.screen.height) ? mHeight : window.screen.height;
    var showtop = 0;
    var showleft = 0;
    if (positionObj == undefined) {
        showtop = (sHeight - height) / 2 * 0.382 + document.documentElement.scrollTop;
        showtop = (showtop < 0) ? 120 : showtop;
        showleft = (sWidth - width) / 2;
        showleft = (showleft < 0) ? 150 : showleft;
        //(showtop < 0) ? 120 : showtop;       
    } else {
        var offset = Offset(positionObj);
        showtop = offset.top + 25;
        showleft = offset.left;
        showleft = (showleft + width > sWidth) ? showleft - width + 60 : showleft;
        showtop = (showtop + height > sHeight) ? showtop - height - 50 : showtop;
    }

    //定义弹出框住结构
    var divBox = document.createElement("span");
    divBox.setAttribute('id', 'divBox');
    divBox.className = 'gSys-msg';
    divBox.style.display = "block";
    document.getElementById("form1").appendChild(divBox);
    //定义弹出框的内容去
    var divMain = document.createElement("span");
    divMain.setAttribute("id", "divMain");
    divMain.className = 'gSys-msg-win';
    divMain.style.display = "block";
    divMain.style.width = width + "px";
    divMain.style.height = height + "px";
    divMain.style.top = showtop + "px";
    divMain.style.left = showleft + "px";
    document.getElementById("divBox").appendChild(divMain);
    //弹出框的标题
    var divHead = document.createElement("span");
    divHead.setAttribute("id", "divHead");
    divHead.className = 'hd';
    divHead.style.display = "block";
    divHead.innerHTML = "<span class='fn-bg rc-l'>&nbsp;</span><h4>&nbsp;" + title + "</h4>";
    divHead.innerHTML = divHead.innerHTML + "<span class='sub txt-14'></span><span class='fn-bg rc-r'></span>";
    var closeA = document.createElement("a");
    closeA.setAttribute("id", "lnkClose");
    closeA.setAttribute("title", "关闭")
    closeA.setAttribute("hidefocus", "true")
    closeA.className = "fn-bg Aclose";
    closeA.innerHTML = "关闭";
    closeA.onclick = function () {
        isShow = false;
        try {
            document.getElementById('ifNoticeAdd').contentWindow.ClearInterval();    //如果存在此方法则执行，若出现异常，继续进行
        }
        catch (e) {
        }
        showElementAll();
        document.getElementById("form1").removeChild(document.getElementById("divBox"));
        if (type == 2) {
            content.innerHTML = divContent.innerHTML;
            content.setAttribute("display", "none");
        }
    }
    divHead.onmousedown = function(e) {
        fDragging(divMain, e);
    }
    document.getElementById("divMain").appendChild(divHead); //绑定到显示区
    document.getElementById("divHead").appendChild(closeA);
    //弹出框的内容
    var divContent = document.createElement("div");
    divContent.setAttribute("id", "divContent");
    divContent.className = 'cont';

    switch (type) {
        case 1:
            var iframe = document.createElement("iframe");
            iframe.style.width = width + 'px';
            iframe.style.height = height + 'px';
            iframe.style.overflow = "hidden";
            iframe.setAttribute("id", "ifNoticeAdd");
            iframe.src = content;
            divContent.appendChild(iframe);
            break;
        case 2: divContent.innerHTML = content.innerHTML;
            content.innerHTML = "";
            divContent.setAttribute("display", ""); break;
        case 3: divContent.innerHTML = content; break;
    }
    document.getElementById("divMain").appendChild(divContent); //绑定到显示区
    //页面的整体背景颜色
    if (positionObj == undefined) {
        var divMask = document.createElement("div");
        divMask.setAttribute("id", "divMask");
        divMask.className = 'mask';
        if (mHeight >= window.screen.height) {
            divMask.style.height = mHeight + "px";
        }
        divMask.style.width = Math.max(document.body.scrollWidth, document.documentElement.scrollWidth) + "px";   //document.documentElement.clientWidth + "px";
        divMask.style.height = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight) + "px";  //document.documentElement.clientHeight + "px";
        divMask.innerHTML = "&nbsp;";
        document.getElementById("divBox").appendChild(divMask);
    }
    document.getElementById("divContent").focus();
    this.Hide = function() {
        isShow = false;
        showElementAll();
        if (document.getElementById("divBox") == undefined)
            return;
        document.getElementById("form1").removeChild(document.getElementById("divBox"));
        if (type == 2) {
            content.innerHTML = divContent.innerHTML;
            content.setAttribute("display", "none");
        }
    }
}
/*************弹出层的操作*********************
content:要现实的内容[url.obj,content]
position:如果不为空，则显示在传过来的对象处，如果为空，剧中
height对象的高度；width:对象的宽度
type:[1:url;2:obj;3:content]
*/

function showChild(title, content, height, width, type, positionObj) {
    if (isShow) {
        return;
    } else {
        isShow = true;
    }
    type = (type == undefined) ? 2 : type;
    height = (height == undefined) ? 600 : height;
    width = (width == undefined) ? 800 : width;
    var sWidth = document.documentElement.scrollWidth;
    var sHeight = document.documentElement.offsetHeight//(document.documentElement.offsetHeight - document.body.offsetHeight > 200) ? document.documentElement.offsetHeight : document.body.offsetHeight;

    var mHeight = document.documentElement.scrollHeight; //(sHeight > screeH) ? sHeight : screeH;
    mHeight = (mHeight > window.screen.height) ? mHeight : window.screen.height;
    var showtop = 0;
    var showleft = 0;
    if (positionObj == undefined) {
        showtop = (sHeight - height) / 2 * 0.618 + document.documentElement.scrollTop;
        showtop = (showtop < 0) ? 120 : showtop;
        showleft = (sWidth - width) / 2;
        showleft = (showleft < 0) ? 150 : showleft;
    } else {
        var offset = Offset(positionObj);
        showtop = offset.top + 25;
        showleft = offset.left;
        showleft = (showleft + width > sWidth) ? showleft - width + 60 : showleft;
        showtop = (showtop + height > sHeight) ? showtop - height - 50 : showtop;
    }

    //定义弹出框住结构
    var divBox = document.createElement("div");
    divBox.setAttribute('id', 'divBox');
    divBox.className = 'gSys-msg';
    document.getElementById("form1").appendChild(divBox);
    //定义弹出框的内容去
    var divMain = document.createElement("div");
    divMain.setAttribute("id", "divMain");
    divMain.className = 'gSys-msg-win';
    divMain.style.width = width + "px";
    divMain.style.height = height + "px";
    divMain.style.top = showtop + "px";
    divMain.style.left = showleft + "px";
    document.getElementById("divBox").appendChild(divMain);
    //弹出框的标题
    var divHead = document.createElement("div");
    divHead.setAttribute("id", "divHead");
    divHead.className = 'fn-bgx bg-main-2 hd';
    divHead.innerHTML = "<span class='fn-bg rc-l'>&nbsp;</span><h4>&nbsp;" + title + "</h4>";
    divHead.innerHTML = divHead.innerHTML + "<span class='sub txt-14'></span><span class='fn-bg rc-r'></span>";
    var closeA = document.createElement("a");
    closeA.setAttribute("id", "lnkClose");
    closeA.setAttribute("title", "关闭")
    closeA.setAttribute("hidefocus", "true")
    closeA.className = "fn-bg Aclose";
    closeA.innerHTML = "关闭";
    closeA.onclick = function () {
        isShow = false;
        document.getElementById("form1").removeChild(document.getElementById("divBox"));
        if (type == 2) {
            content.innerHTML = divContent.innerHTML;
            content.setAttribute("display", "none");
        }
    }
    divHead.onmousedown = function(e) {
        fDragging(divMain, e);
    }
    document.getElementById("divMain").appendChild(divHead); //绑定到显示区
    document.getElementById("divHead").appendChild(closeA);
    //弹出框的内容
    var divContent = document.createElement("div");
    divContent.setAttribute("id", "divContent");
    divContent.className = 'cont';

    switch (type) {
        case 1:
            var iframe = document.createElement("iframe");
            iframe.style.width = width + 'px';
            iframe.style.height = height + 'px';
            iframe.style.overflow = "hidden";
            iframe.setAttribute("id", "ifNoticeAdd");
            iframe.src = content;
            divContent.appendChild(iframe);
            break;
        case 2: divContent.innerHTML = content.innerHTML;
            content.innerHTML = "";
            divContent.setAttribute("display", ""); break;
        case 3: divContent.innerHTML = content; break;
    }
    document.getElementById("divMain").appendChild(divContent); //绑定到显示区
    //页面的整体背景颜色
    if (positionObj == undefined) {
        var divMask = document.createElement("div");
        divMask.setAttribute("id", "divMask");
        divMask.className = 'mask';
        if (mHeight >= window.screen.height) {
            divMask.style.height = mHeight + "px";
        }
        divMask.innerHTML = "&nbsp;";
        document.getElementById("divBox").appendChild(divMask);
    }
    document.getElementById("divContent").focus();
    this.Hide = function() {
        isShow = false;
        if (document.getElementById("divBox") == undefined)
            return;
        document.getElementById("form1").removeChild(document.getElementById("divBox"));
        if (type == 2) {
            content.innerHTML = divContent.innerHTML;
            content.setAttribute("display", "none");
        }
    }
}
/*
函数 fDragging(obj, e) 的各参数解释:
obj: HTML元素对象, 要拖曳的元素
e: 指定为 event 对象, 主要为兼容 Firefox
*/
function fDragging(obj, e) {
    if (!e) e = window.event;


    var x = parseInt(obj.style.left);
    var y = parseInt(obj.style.top);

    var x_ = e.clientX - x;
    var y_ = e.clientY - y;

    if (document.addEventListener) {
        document.addEventListener('mousemove', inFmove, true);
        document.addEventListener('mouseup', inFup, true);
    } else if (document.attachEvent) {
        document.attachEvent('onmousemove', inFmove);
        document.attachEvent('onmouseup', inFup);
    }

    inFstop(e);
    inFabort(e)

    function inFmove(e) {
        if (!e) e = window.event;
        if (e.clientX+ obj.style.posWidth - x_-20 > 0 && e.clientY  - y_ > 0) {
            obj.style.left = e.clientX - x_ + 'px';
            obj.style.top = e.clientY - y_ + 'px';
        }

        inFstop(e);
    } // shawl.qiu script
    function inFup(e) {
        var evt;
        if (!e) e = window.event;

        if (document.removeEventListener) {
            document.removeEventListener('mousemove', inFmove, true);
            document.removeEventListener('mouseup', inFup, true);
        } else if (document.detachEvent) {
            document.detachEvent('onmousemove', inFmove);
            document.detachEvent('onmouseup', inFup);
        }

        inFstop(e);
    } // shawl.qiu script

    function inFstop(e) {
        if (e.stopPropagation) return e.stopPropagation();
        else return e.cancelBubble = true;
    } // shawl.qiu script
    function inFabort(e) {
        if (e.preventDefault) return e.preventDefault();
        else return e.returnValue = false;
    } // shawl.qiu script
}
//ie6下隐藏元素防遮挡浮动层
function hideElementAll() {
    HideElement("SELECT");
    //HideElement("OBJECT");
    //HideElement("IFRAME");
}
function showElementAll() {
    ShowElement("SELECT");
    //ShowElement("OBJECT");
    //ShowElement("IFRAME");
}
function HideElement(strElementTagName) {
    try {
        for (i = 0; i < window.document.getElementsByTagName(strElementTagName).length; i++) {
            var objTemp = window.document.getElementsByTagName(strElementTagName)[i];
            if (objTemp.id.indexOf("shDdl") == -1)
                objTemp.style.visibility = "hidden";
        }
    } catch (e) {
        alert(e.message);
    }
}
function ShowElement(strElementTagName) {
    try {
        for (i = 0; i < window.document.getElementsByTagName(strElementTagName).length; i++) {
            var objTemp = window.document.getElementsByTagName(strElementTagName)[i];
            objTemp.style.visibility = "visible";
        }
    } catch (e) {
        alert(e.message);
    }
}
//attach(window,"load",function(){alert('111')})
function attach(o, e, f) {
    if (document.attachEvent)
        o.attachEvent("on" + e, f);
    else if (document.addEventListener)
        o.addEventListener(e, f);
}
function tabs(Id, Ids, activeClass, normalClass) {
    for (var i = 0; i < Ids.length; i++) {
        if (Ids[i] == Id) {
            document.getElementById('tab' + Id).className = activeClass;
        }
        else {
            document.getElementById('tab' + Ids[i]).className = normalClass;
        }
    }
}